package org.pzy.java.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author: DRevelation
 * @Date: 2022/6/17 10:14
 */
public class FastJsonDemo {
    public static void main(String[] args) {

        List<String> books = new ArrayList<>();
        books.add("Java");
        books.add("Go");
        User user = User.builder().id(1).name("abc").email("abc@123.com").books(books).other(123L).build();

        String fastjson = JSON.toJSONString(user);
        System.out.println("fastjson = " + fastjson);

        User user1 = JSON.parseObject(fastjson, User.class);
        System.out.println("user1 = " + user1);

        JSONObject object = JSONObject.parseObject(fastjson);
        String name = object.getString("name");
        System.out.println("name = " + name);

        JSONArray books1 = object.getJSONArray("books");
        System.out.println("books1 = " + books1);
        System.out.println("books1[0] = " + books1.getString(0));

        Long.valueOf(null);

        System.out.println(Objects.equals("", ""));
    }
}
